# server/src/knowledge/model.py
from sqlalchemy import Column, Integer, String, Text, DateTime, JSON
from sqlalchemy.ext.declarative import declarative_base
from datetime import datetime

Base = declarative_base()

class Document(Base):
    """文档存储模型"""
    __tablename__ = "documents"
    
    id = Column(Integer, primary_key=True, index=True)
    filename = Column(String(255), nullable=False)
    file_type = Column(String(50), nullable=False)  # md/pdf/docx
    content = Column(Text, nullable=False)         # 解析后的文本内容
    metadata = Column(JSON, default={})            # 原始元数据
    created_at = Column(DateTime, default=datetime.utcnow)
    updated_at = Column(DateTime, onupdate=datetime.utcnow)
    is_deleted = Column(Integer, default=0)        # 软删除标记

class KnowledgeBaseItem(Base):
    """知识库条目关联表"""
    __tablename__ = "knowledge_base_items"
    
    id = Column(Integer, primary_key=True)
    doc_id = Column(Integer, index=True)          # 关联文档ID
    embedding = Column(Text)                      # 文本向量（预留）
    created_at = Column(DateTime, default=datetime.utcnow)